
// 创建或切换数据库
db = db.getSiblingDB('myapp');

// 创建集合(相当于SQL的表)
db.createCollection('users');
db.createCollection('products');

// 插入初始数据(相当于INSERT)
db.users.insertMany([
  { name: "Admin", email: "admin@example.com", role: "admin" },
  { name: "User1", email: "user1@example.com", role: "user" }
]);

db.products.insertMany([
  { name: "Product A", price: 99.99, stock: 100 },
  { name: "Product B", price: 199.99, stock: 50 }
]);

// 创建索引(相当于CREATE INDEX)
db.users.createIndex({ email: 1 }, { unique: true });
db.products.createIndex({ name: 1 });

print("Database initialized successfully!");